package demo.gaobo.com.myapplication.fragment;

import android.content.Intent;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.bingoogolapple.bgabanner.BGABanner;
import demo.gaobo.com.myapplication.R;
import demo.gaobo.com.myapplication.activity.ClassificationActivity;
import demo.gaobo.com.myapplication.activity.SearchActivity;
import demo.gaobo.com.myapplication.base.BaseFragment;
import demo.gaobo.com.myapplication.base.BasePresenter;
import demo.gaobo.com.myapplication.manager.ImageLoaderManager;

/**
 * Created by Hugh on 2018/9/25.
 */

public class HomeFragment extends BaseFragment {
    @Bind(R.id.banner)
    BGABanner banner;
    @Bind(R.id.iv_helmet)
    ImageView ivHelmet;
    @Bind(R.id.ll_helmet)
    LinearLayout llHelmet;
    @Bind(R.id.iv_hair)
    ImageView ivHair;
    @Bind(R.id.ll_hair)
    LinearLayout llHair;
    @Bind(R.id.iv_health)
    ImageView ivHealth;
    @Bind(R.id.ll_health)
    LinearLayout llHealth;
    @Bind(R.id.iv_other)
    ImageView ivOther;
    @Bind(R.id.ll_other)
    LinearLayout llOther;
    private List<String> bannerData;

    @NonNull
    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int provideContentViewId() {
        return R.layout.fragment_home;
    }

    @Override
    public void initView(View rootView) {
        bannerData = new ArrayList<>();
        bannerData.add("https://images.unsplash.com/photo-1537759936999-5a1b63904966?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=c234000fe85288996d1eaed9a92b081f&auto=format&fit=crop&w=500&q=60");
        bannerData.add("https://images.unsplash.com/photo-1537724903888-33a8c4aadb8d?ixlib=rb-0.3.5&s=961bd3d2b081a0c14ea138a0d583a42c&auto=format&fit=crop&w=612&q=80");
        bannerData.add("https://images.unsplash.com/photo-1537767017444-30935148a2f0?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=46b177f3f1bb18966159081179b30da4&auto=format&fit=crop&w=500&q=60");
        bannerData.add("https://images.unsplash.com/photo-1537796298747-3a1ef0886dc3?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=c561a4a772932249ef2d9d63918a7d4c&auto=format&fit=crop&w=500&q=60");
        getBannerDataSuccess(bannerData);
    }


    public void getBannerDataSuccess(List<String> bannerData) {
        //设置轮播图
        banner.setData(R.layout.item_banner, bannerData, null);
        banner.setAdapter(new BGABanner.Adapter<View, String>() {
            @Override
            public void fillBannerItem(BGABanner banner, View itemView, String model, int position) {
                Log.e(TAG, "fillBannerItem: " + model);
                ImageView imageView = (ImageView) itemView.findViewById(R.id.imageView);
                ImageLoaderManager.LoadImage(getContext(), model, imageView);
            }
        });
        banner.setDelegate(new BGABanner.Delegate<View, String>() {
            @Override
            public void onBannerItemClick(BGABanner banner, View itemView, String model, int position) {
                Toast.makeText(getActivity(), "" + position, Toast.LENGTH_SHORT).show();
                startActivity(new Intent(getActivity(), SearchActivity.class));
            }
        });
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }


    @OnClick({R.id.ll_helmet, R.id.ll_hair, R.id.ll_health, R.id.ll_other})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.ll_helmet:
                startActivity(new Intent(getActivity(), ClassificationActivity.class));
                break;
            case R.id.ll_hair:
                startActivity(new Intent(getActivity(), ClassificationActivity.class));
                break;
            case R.id.ll_health:
                startActivity(new Intent(getActivity(), ClassificationActivity.class));
                break;
            case R.id.ll_other:
                startActivity(new Intent(getActivity(), ClassificationActivity.class));
                break;
        }
    }
}
